/**
* Created by wust on 2020-07-03 20:26:45.
*/
<template>
	<el-form ref="formModel" :model="formModel" :rules="rules" label-width="120px" style="width:70%;"
	 @submit.native.prevent>
		<el-form-item label="name" prop="name">
			<el-input v-model="formModel.name"></el-input>
		</el-form-item>
		<el-form-item label="value" prop="value">
			<select class="form-control" v-data-dictionary-directive:A1003 v-model="formModel.value">
			</select>
		</el-form-item>

		<el-form-item style="text-align: left;">
			<el-button type="primary" @click="onSubmit('formModel')" :loading="submitting">提交</el-button>
		</el-form-item>
	</el-form>
</template>
<script>
import Vue from 'vue'

export default {
  name: 'test-create',
  data () {
    return {
      submitting: false,
      formModel: {
        name: null,
        value: null

      },
      rules: {}
    }
  },
  methods: {
    onSubmit: function (formData) {
      this.$refs[formData].validate((valid) => {
        if (!valid) {} else {
          this.submitting = true
          Vue.$ajax({
            method: 'post',
            url: Vue.$demo2ServerURL + '/web/v1/TestController',
            data: this.formModel
          }).then(res => {
            this.submitting = false
            if (res.data.flag !== 'SUCCESS') {
              if (!Vue.$isNullOrIsBlankOrIsUndefined(res.data.message)) {
                this.$message({
                  message: res.data.message,
                  type: 'warning'
                })
              }
            } else {
              this.$message({
                message: res.data.message,
                type: 'success'
              })
              this.resetForm('formModel')
            }
          })
        }
      })
    },
    resetForm (formData) {
      this.$refs[formData].resetFields()
    }
  }
}
</script>
